import torch
from torch.nn import ReLU, Sigmoid, SELU, Linear
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
from torchvision.datasets import CIFAR10
from torchvision.transforms import ToTensor


class ReluModule(torch.nn.Module):
    def __init__(self, input, out):
        super().__init__()
        self.liner = Linear(input, out)

    def forward(self, input):
        return self.liner(input)

module = None
dataset = CIFAR10(root="datasets", train=False, transform=ToTensor(), download=True)
dataloader = DataLoader(dataset=dataset, batch_size=64, drop_last=False)

writer = SummaryWriter("logs")
step = 0

for imgs, targets in dataloader:
    input = torch.reshape(imgs, (1, 1, 1, -1))
    if module is None:
        module = ReluModule(input.shape[-1], 10)
    output = module(input)
    # print(output.shape)
    writer.add_images("input", imgs, step)
    writer.add_images("linear", output, step)
    step += 1

writer.close()
print("success")
